#include "sdl_print.h"

static TTF_Font     *init_print(void)
{
    TTF_Font        *font = NULL;

    if (TTF_Init() == -1)
    {
        fprintf(stderr, "TTF_Init : %s\n", TTF_GetError());
        exit(EXIT_FAILURE);
    }
    font = TTF_OpenFont("/usr/share/fonts/truetype/DejaVuSansMono.ttf", 20);
    return (font);
}

/**
** @brief Get an SDL_Surface with the text we what to print
**
** @param String we what to print
**
** @return SDL_Surface with the text to print
*/
SDL_Surface         *texte_surface(char *arg)
{
    SDL_Surface     *text = NULL;
    SDL_Color       white = {.r = 255, .g = 255, .b = 255};
    TTF_Font        *font = NULL;

    font = init_print();
    white = white;
    arg = arg;

    text = TTF_RenderText_Blended(font, arg, white);
    TTF_CloseFont(font);
    return (text);
}

/**
** @brief Liberate the SDL_Surface with the textt
**
** @param Surface with the text
*/
void close_print(SDL_Surface *text)
{
    SDL_FreeSurface(text);
    TTF_Quit();
}
